gtk: Check return value of compute_bounds()
authorBenjamin Otte <otte@redhat.com>
Wed, 20 Feb 2019 03:53:47 +0000 (04:53 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 20 Feb 2019 04:26:31 +0000 (05:26 +0100)
Half of these calls will completely break if anybody ever uses CSS
transforms with them, but hey...

19 files changed:
gtk/gtkcontainer.c
gtk/gtkentry.c
gtk/gtkgesturestylus.c
gtk/gtklistbox.c
gtk/gtkmenu.c
gtk/gtknotebook.c
gtk/gtkpaned.c
gtk/gtkpopover.c
gtk/gtkrange.c
gtk/gtkscale.c
gtk/gtkscrolledwindow.c
gtk/gtkswitch.c
gtk/gtktooltip.c
gtk/gtktreeviewcolumn.c
gtk/gtkwidget.c
gtk/gtkwidgetfocus.c
gtk/gtkwidgetpaintable.c
gtk/inspector/fpsoverlay.c
tests/testwidgettransforms.c

index f1ef23e8e4a95b348dc5fe936fa7c16c3f86bbb1..4c6219ec8aa4f607e36477f5ed1ec55b17868643 100644 (file)
@@ -1653,7 +1653,8 @@ gtk_container_real_set_focus_child (GtkContainer *container,
                                                  0, 0, &x, &y))
             return;
 
-          gtk_widget_compute_bounds (child, child, &child_bounds);
+          if (!gtk_widget_compute_bounds (child, child, &child_bounds))
+            return;
 
           if (vadj)
             gtk_adjustment_clamp_page (vadj, y, y + child_bounds.size.height);
index 035b81d82874a86443c268e7de5bd4bda4150afa..854410dddf3c50f0cc304bc5c01bd284d2456e33 100644 (file)
@@ -2889,18 +2889,16 @@ gtk_entry_get_icon_area (GtkEntry             *entry,
 {
   GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
   EntryIconInfo *icon_info;
+  graphene_rect_t r;
 
   g_return_if_fail (GTK_IS_ENTRY (entry));
   g_return_if_fail (icon_area != NULL);
 
   icon_info = priv->icons[icon_pos];
 
-  if (icon_info)
+  if (icon_info &&
+      gtk_widget_compute_bounds (icon_info->widget, GTK_WIDGET (entry), &r))
     {
-      graphene_rect_t r;
-
-      gtk_widget_compute_bounds (icon_info->widget, GTK_WIDGET (entry), &r);
-
       *icon_area = (GdkRectangle){
         floorf (r.origin.x),
         floorf (r.origin.y),
index 4c9d704f6d88c52ec3affc192d9032ca080e9b4c..2122f08e090b17be366a0cf6a93c0c45377cf398 100644 (file)
@@ -284,13 +284,19 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus  *gesture,
 
       g_array_append_val (backlog_array, *time_coord);
       time_coord = &g_array_index (backlog_array, GdkTimeCoord, backlog_array->len - 1);
-      gtk_widget_compute_point (gtk_get_event_widget (event),
-                                gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
-                                &GRAPHENE_POINT_INIT (time_coord->axes[GDK_AXIS_X],
-                                                      time_coord->axes[GDK_AXIS_Y]),
-                                &p);
-      time_coord->axes[GDK_AXIS_X] = p.x;
-      time_coord->axes[GDK_AXIS_Y] = p.y;
+      if (gtk_widget_compute_point (gtk_get_event_widget (event),
+                                    gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)),
+                                    &GRAPHENE_POINT_INIT (time_coord->axes[GDK_AXIS_X],
+                                                          time_coord->axes[GDK_AXIS_Y]),
+                                    &p))
+        {
+          time_coord->axes[GDK_AXIS_X] = p.x;
+          time_coord->axes[GDK_AXIS_Y] = p.y;
+        }
+      else
+        {
+          g_array_set_size (backlog_array, backlog_array->len - 1);
+        }
     }
 
   *n_elems = backlog_array->len;
index 274956d8f81f0dd1cd5bb4a49cbeaafbb1445f90..f6ccfb1931b52c28fb63ad89147511d6077ac68a 100644 (file)
@@ -1443,7 +1443,9 @@ ensure_row_visible (GtkListBox    *box,
   if (!priv->adjustment)
     return;
 
-  gtk_widget_compute_bounds (GTK_WIDGET (row), GTK_WIDGET (box), &rect);
+  if (!gtk_widget_compute_bounds (GTK_WIDGET (row), GTK_WIDGET (box), &rect))
+    return;
+
   y = rect.origin.y;
   height = rect.size.height;
 
@@ -1451,9 +1453,11 @@ ensure_row_visible (GtkListBox    *box,
   header = ROW_PRIV (row)->header;
   if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header))
     {
-      gtk_widget_compute_bounds (header, GTK_WIDGET (box), &rect);
-      y = rect.origin.y;
-      height += rect.size.height;
+      if (gtk_widget_compute_bounds (header, GTK_WIDGET (box), &rect))
+        {
+          y = rect.origin.y;
+          height += rect.size.height;
+        }
     }
 
   gtk_adjustment_clamp_page (priv->adjustment, y, y + height);
index c12b19bcf3b32fec468049c33dfef19b1c1701ed..247dd4f12eeca0b57faaa18e7a33f2ed65e7b70a 100644 (file)
@@ -2812,7 +2812,9 @@ definitely_within_item (GtkMenu   *menu,
   int w, h;
   graphene_rect_t bounds;
 
-  gtk_widget_compute_bounds (widget, GTK_WIDGET (menu), &bounds);
+  if (!gtk_widget_compute_bounds (widget, GTK_WIDGET (menu), &bounds))
+    return FALSE;
+
   w = bounds.size.width;
   h = bounds.size.height;
 
index decf8c61cdcce945e6dbb0dfb459ac8daf3bc55c..af69ab3000672bd3c4f45b1d0592d2e374054544 100644 (file)
@@ -1628,10 +1628,9 @@ gtk_notebook_get_tab_area_position (GtkNotebook     *notebook,
 
   if (priv->show_tabs && gtk_notebook_has_current_page (notebook))
     {
-      gtk_widget_compute_bounds (priv->header_widget,
-                                 GTK_WIDGET (notebook),
-                                 rectangle);
-      return TRUE;
+      return gtk_widget_compute_bounds (priv->header_widget,
+                                        GTK_WIDGET (notebook),
+                                        rectangle);
     }
   else
     {
@@ -2094,9 +2093,10 @@ gtk_notebook_get_arrow (GtkNotebook *notebook,
           if (priv->arrow_widget[i] == NULL)
             continue;
 
-          gtk_widget_compute_bounds (priv->arrow_widget[i],
-                                     GTK_WIDGET (notebook),
-                                     &arrow_bounds);
+          if (!gtk_widget_compute_bounds (priv->arrow_widget[i],
+                                          GTK_WIDGET (notebook),
+                                          &arrow_bounds))
+            continue;
 
           if (graphene_rect_contains_point (&arrow_bounds,
                                             &(graphene_point_t){x, y}))
@@ -2184,7 +2184,8 @@ in_tabs (GtkNotebook *notebook,
   GtkNotebookPrivate *priv = notebook->priv;
   graphene_rect_t tabs_bounds;
 
-  gtk_widget_compute_bounds (priv->tabs_widget, GTK_WIDGET (notebook), &tabs_bounds);
+  if (!gtk_widget_compute_bounds (priv->tabs_widget, GTK_WIDGET (notebook), &tabs_bounds))
+    return FALSE;
 
   return graphene_rect_contains_point (&tabs_bounds,
                                        &(graphene_point_t){x, y});
@@ -2208,8 +2209,8 @@ get_tab_at_pos (GtkNotebook *notebook,
       if (!gtk_notebook_page_tab_label_is_visible (page))
         continue;
 
-      gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &bounds);
-
+      if (!gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &bounds))
+        continue;
 
       if (graphene_rect_contains_point (&bounds, &(graphene_point_t){x, y}))
         return children;
@@ -2285,10 +2286,14 @@ gtk_notebook_gesture_pressed (GtkGestureMultiPress *gesture,
           priv->drag_begin_x = priv->mouse_x;
           priv->drag_begin_y = priv->mouse_y;
 
-          gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds);
-
-          priv->drag_offset_x = priv->drag_begin_x - tab_bounds.origin.x;
-          priv->drag_offset_y = priv->drag_begin_y - tab_bounds.origin.y;
+          /* tab bounds get set to empty, which is fine */
+          priv->drag_offset_x = priv->drag_begin_x;
+          priv->drag_offset_y = priv->drag_begin_y;
+          if (gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds))
+            {
+              priv->drag_offset_x -= tab_bounds.origin.x;
+              priv->drag_offset_y -= tab_bounds.origin.y;
+            }
         }
     }
 }
@@ -2373,10 +2378,9 @@ get_drop_position (GtkNotebook *notebook)
   y = priv->mouse_y;
 
   is_rtl = gtk_widget_get_direction ((GtkWidget *) notebook) == GTK_TEXT_DIR_RTL;
-  children = priv->children;
   last_child = NULL;
 
-  while (children)
+  for (children = priv->children; children; children = children->next)
     {
       page = children->data;
 
@@ -2387,7 +2391,8 @@ get_drop_position (GtkNotebook *notebook)
         {
           graphene_rect_t tab_bounds;
 
-          gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds);
+          if (!gtk_widget_compute_bounds (page->tab_widget, GTK_WIDGET (notebook), &tab_bounds))
+            continue;
 
           switch (priv->tab_pos)
             {
@@ -2418,8 +2423,6 @@ get_drop_position (GtkNotebook *notebook)
 
           last_child = children->next;
         }
-
-      children = children->next;
     }
 
   return last_child;
@@ -2895,10 +2898,10 @@ gtk_notebook_drag_begin (GtkWidget        *widget,
   gtk_widget_unparent (tab_label);
 
   priv->dnd_child = tab_label;
-  gtk_widget_compute_bounds (priv->dnd_child, priv->dnd_child, &bounds);
-  gtk_widget_set_size_request (priv->dnd_child,
-                               ceilf (bounds.size.width),
-                               ceilf (bounds.size.height));
+  if (gtk_widget_compute_bounds (priv->dnd_child, priv->dnd_child, &bounds))
+    gtk_widget_set_size_request (priv->dnd_child,
+                                 ceilf (bounds.size.width),
+                                 ceilf (bounds.size.height));
 
   gtk_style_context_add_class (gtk_widget_get_style_context (priv->dnd_child), "background");
 
@@ -4933,7 +4936,8 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook          *notebook,
       break;
     }
 
-  gtk_widget_compute_bounds (priv->cur_page->tab_widget, priv->cur_page->tab_widget, &drag_bounds);
+  if (!gtk_widget_compute_bounds (priv->cur_page->tab_widget, priv->cur_page->tab_widget, &drag_bounds))
+    graphene_rect_init_from_rect (&drag_bounds, graphene_rect_zero ());
 
   left_x   = CLAMP (priv->mouse_x - priv->drag_offset_x,
                     allocation->x, allocation->x + allocation->width - drag_bounds.size.width);
index 2cd216657e3641a74b6558841b127af2faf124f5..9fc18c9667dc9718ac6d0d9b7b3175b2fa8eebf9 100644 (file)
@@ -293,7 +293,8 @@ get_handle_area (GtkPaned        *paned,
   GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned);
   int extra = 0;
 
-  gtk_widget_compute_bounds (priv->handle_widget, GTK_WIDGET (paned), area);
+  if (!gtk_widget_compute_bounds (priv->handle_widget, GTK_WIDGET (paned), area))
+    return;
 
   if (!gtk_paned_get_wide_handle (paned))
     extra = HANDLE_EXTRA_SIZE;
index 69336460b939dc20ad5272d2b4094a4ebb71758d..bec65410f032be6c7de3eae43ea27f0acddb3cd8 100644 (file)
@@ -338,9 +338,8 @@ gesture_released (GtkGestureMultiPress *gesture,
     return;
 
   child = gtk_bin_get_child (GTK_BIN (popover));
-  gtk_widget_compute_bounds (child, GTK_WIDGET (popover), &child_bounds);
-
-  if (!graphene_rect_contains_point (&child_bounds,
+  if (!gtk_widget_compute_bounds (child, GTK_WIDGET (popover), &child_bounds) ||
+      !graphene_rect_contains_point (&child_bounds,
                                      &(graphene_point_t){x, y}))
     gtk_popover_popdown (popover);
 }
@@ -2147,7 +2146,8 @@ gtk_popover_get_pointing_to (GtkPopover   *popover,
     {
       graphene_rect_t r;
 
-      gtk_widget_compute_bounds (priv->widget, priv->widget, &r);
+      if (!gtk_widget_compute_bounds (priv->widget, priv->widget, &r))
+        return FALSE;
 
       rect->x = floorf (r.origin.x);
       rect->y = floorf (r.origin.y);
index 7af7f80a2c2a4eff642da62ffcaca40d875223bb..a26e882ec976c17c1be59a939ffd1dbeeb28334b 100644 (file)
@@ -920,14 +920,19 @@ gtk_range_get_range_rect (GtkRange     *range,
   g_return_if_fail (GTK_IS_RANGE (range));
   g_return_if_fail (range_rect != NULL);
 
-  gtk_widget_compute_bounds (priv->trough_widget, GTK_WIDGET (range), &r);
-
-  *range_rect = (GdkRectangle) {
-    floorf (r.origin.x),
-    floorf (r.origin.y),
-    ceilf (r.size.width),
-    ceilf (r.size.height),
-  };
+  if (!gtk_widget_compute_bounds (priv->trough_widget, GTK_WIDGET (range), &r))
+    {
+      *range_rect = (GdkRectangle) { 0, 0, 0, 0 };
+    }
+  else
+    {
+      *range_rect = (GdkRectangle) {
+        floorf (r.origin.x),
+        floorf (r.origin.y),
+        ceilf (r.size.width),
+        ceilf (r.size.height),
+      };
+    }
 }
 
 /**
@@ -953,7 +958,14 @@ gtk_range_get_slider_range (GtkRange *range,
 
   g_return_if_fail (GTK_IS_RANGE (range));
 
-  gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds);
+  if (!gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds))
+    {
+      if (slider_start)
+        *slider_start = 0;
+      if (slider_end)
+        *slider_end = 0;
+      return;
+    }
 
   if (priv->orientation == GTK_ORIENTATION_VERTICAL)
     {
@@ -1745,7 +1757,8 @@ coord_to_value (GtkRange *range,
   gint    slider_length;
   graphene_rect_t slider_bounds;
 
-  gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds);
+  if (!gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds))
+    graphene_rect_init (&slider_bounds, 0, 0, gtk_widget_get_width (priv->trough_widget), gtk_widget_get_height (priv->trough_widget));
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
@@ -1804,7 +1817,8 @@ gtk_range_key_controller_key_pressed (GtkEventControllerKey *controller,
     {
       graphene_rect_t slider_bounds;
 
-      gtk_widget_compute_bounds (priv->slider_widget, priv->trough_widget, &slider_bounds);
+      if (!gtk_widget_compute_bounds (priv->slider_widget, priv->trough_widget, &slider_bounds))
+        return GDK_EVENT_STOP;
 
       if (priv->orientation == GTK_ORIENTATION_VERTICAL)
         priv->slide_initial_slider_position = slider_bounds.origin.y;
@@ -1877,7 +1891,6 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
   guint button;
   GdkModifierType state_mask;
   GtkWidget *mouse_location;
-  graphene_rect_t slider_bounds;
 
   if (!gtk_widget_has_focus (widget))
     gtk_widget_grab_focus (widget);
@@ -1891,8 +1904,6 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
   source_device = gdk_event_get_source_device ((GdkEvent *) event);
   source = gdk_device_get_source (source_device);
 
-  gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds);
-
   g_object_get (gtk_widget_get_settings (widget),
                 "gtk-primary-button-warps-slider", &primary_warps,
                 NULL);
@@ -1931,13 +1942,15 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
             (!primary_warps && button == GDK_BUTTON_MIDDLE)))
     {
       int slider_range_x, slider_range_y;
+      graphene_rect_t slider_bounds;
 
       gtk_widget_translate_coordinates (priv->trough_widget, widget,
                                         priv->slider_x, priv->slider_y,
                                         &slider_range_x, &slider_range_y);
 
       /* If we aren't fixed, center on the slider. I.e. if this is not a scale... */
-      if (!priv->slider_size_fixed)
+      if (!priv->slider_size_fixed &&
+          gtk_widget_compute_bounds (priv->slider_widget, priv->slider_widget, &slider_bounds))
         {
           slider_range_x += (slider_bounds.size.width  / 2);
           slider_range_y += (slider_bounds.size.height / 2);
@@ -2012,6 +2025,7 @@ update_slider_position (GtkRange *range,
                         gint      mouse_y)
 {
   GtkRangePrivate *priv = gtk_range_get_instance_private (range);
+  graphene_rect_t trough_bounds;
   gdouble delta;
   gdouble c;
   gdouble new_value;
@@ -2025,17 +2039,15 @@ update_slider_position (GtkRange *range,
   gtk_widget_translate_coordinates (GTK_WIDGET (range), priv->trough_widget,
                                     mouse_x, mouse_y, &mouse_x, &mouse_y);
 
-  if (priv->zoom)
+  if (priv->zoom && 
+      gtk_widget_compute_bounds (priv->trough_widget, priv->trough_widget, &trough_bounds))
     {
-      graphene_rect_t trough_bounds;
-
-      gtk_widget_compute_bounds (priv->trough_widget, priv->trough_widget, &trough_bounds);
-
       zoom = MIN(1.0, (priv->orientation == GTK_ORIENTATION_VERTICAL ?
                        trough_bounds.size.height : trough_bounds.size.width) /
                        (gtk_adjustment_get_upper (priv->adjustment) -
                         gtk_adjustment_get_lower (priv->adjustment) -
                         gtk_adjustment_get_page_size (priv->adjustment)));
+
       /* the above is ineffective for scales, so just set a zoom factor */
       if (zoom == 1.0)
         zoom = 0.25;
@@ -2048,7 +2060,8 @@ update_slider_position (GtkRange *range,
     {
       graphene_rect_t slider_bounds;
 
-      gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds);
+      if (!gtk_widget_compute_bounds (priv->slider_widget, GTK_WIDGET (range), &slider_bounds))
+        graphene_rect_init (&slider_bounds, 0, 0, 0, 0);
 
       if (priv->orientation == GTK_ORIENTATION_VERTICAL)
         priv->slide_initial_slider_position = (zoom * (mouse_y - priv->slide_initial_coordinate_delta) - slider_bounds.origin.y) / (zoom - 1.0);
index 9d3673e71534c47170e4d94ee92f575850aabf5b..29607a9ccaf430dcd50ae36b356e1f6f87d34b34 100644 (file)
@@ -336,7 +336,8 @@ gtk_scale_allocate_value (GtkScale *scale)
   range_height = gtk_widget_get_height (widget);
 
   slider_widget = gtk_range_get_slider_widget (range);
-  gtk_widget_compute_bounds (slider_widget, widget, &slider_bounds);
+  if (!gtk_widget_compute_bounds (slider_widget, widget, &slider_bounds))
+    graphene_rect_init (&slider_bounds, 0, 0, gtk_widget_get_width (widget), gtk_widget_get_height (widget));
 
   gtk_widget_measure (priv->value_widget,
                       GTK_ORIENTATION_HORIZONTAL, -1,
@@ -1519,7 +1520,8 @@ gtk_scale_real_get_layout_offsets (GtkScale *scale,
   GtkScalePrivate *priv = gtk_scale_get_instance_private (scale);
   graphene_rect_t value_bounds;
 
-  if (!priv->value_widget)
+  if (!priv->value_widget ||
+      !gtk_widget_compute_bounds (priv->value_widget, GTK_WIDGET (scale), &value_bounds))
     {
       *x = 0;
       *y = 0;
@@ -1527,7 +1529,6 @@ gtk_scale_real_get_layout_offsets (GtkScale *scale,
       return;
     }
 
-  gtk_widget_compute_bounds (priv->value_widget, GTK_WIDGET (scale), &value_bounds);
 
   *x = value_bounds.origin.x;
   *y = value_bounds.origin.y;
index 8e8f78e35bc0a816f9db4c3129b76d6837fb7656..ea1b402c4b5c1129aa7b31efe66ad0704a9a70b6 100644 (file)
@@ -1046,7 +1046,8 @@ coords_close_to_indicator (GtkScrolledWindow *sw,
   graphene_rect_t indicator_bounds;
   gint distance;
 
-  gtk_widget_compute_bounds (indicator->scrollbar, GTK_WIDGET (sw), &indicator_bounds);
+  if (!gtk_widget_compute_bounds (indicator->scrollbar, GTK_WIDGET (sw), &indicator_bounds))
+    return FALSE;
 
   if (indicator->over)
     distance = INDICATOR_FAR_DISTANCE;
index 4bdfb5094fef6019450bb2c38f72dff6e7edce9a..eefa49c7085c408863c64ecaa6c7a7a0abc36260 100644 (file)
@@ -191,7 +191,9 @@ gtk_switch_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
   GtkSwitchPrivate *priv = gtk_switch_get_instance_private (sw);
   graphene_rect_t switch_bounds;
 
-  gtk_widget_compute_bounds (GTK_WIDGET (sw), GTK_WIDGET (sw), &switch_bounds);
+  if (!gtk_widget_compute_bounds (GTK_WIDGET (sw), GTK_WIDGET (sw), &switch_bounds))
+    return;
+
   gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
 
   /* If the press didn't happen in the draggable handle,
index 22fafbf47b3161b506cf4581f2848c515d2e91a1..592d56d88aefb4ef0a5d7b396e28943247d8a98d 100644 (file)
@@ -585,11 +585,17 @@ gtk_tooltip_position (GtkTooltip *tooltip,
   tooltip->tooltip_widget = new_tooltip_widget;
 
   toplevel = _gtk_widget_get_toplevel (new_tooltip_widget);
-  gtk_widget_compute_bounds (new_tooltip_widget, toplevel, &anchor_bounds);
-  anchor_rect = (GdkRectangle) {
-    floorf (anchor_bounds.origin.x), floorf (anchor_bounds.origin.y),
-    ceilf (anchor_bounds.size.width), ceilf (anchor_bounds.size.height)
-  };
+  if (gtk_widget_compute_bounds (new_tooltip_widget, toplevel, &anchor_bounds))
+    {
+      anchor_rect = (GdkRectangle) {
+        floorf (anchor_bounds.origin.x), floorf (anchor_bounds.origin.y),
+        ceilf (anchor_bounds.size.width), ceilf (anchor_bounds.size.height)
+      };
+    }
+  else
+    {
+      anchor_rect = (GdkRectangle) { 0, 0, 0, 0 };
+    }
 
   settings = gtk_settings_get_for_display (display);
   g_object_get (settings,
index aa730c8f9bcf1706edcc1ab8b4d09baefc6bb062..674cb7696bdb65b4d19935102bb9861a9ce356aa 100644 (file)
@@ -3060,7 +3060,8 @@ _gtk_tree_view_column_coords_in_resize_rect (GtkTreeViewColumn *column,
       !priv->visible)
     return FALSE;
 
-  gtk_widget_compute_bounds (priv->button, priv->tree_view, &button_bounds);
+  if (!gtk_widget_compute_bounds (priv->button, priv->tree_view, &button_bounds))
+    return FALSE;
 
   if (gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_LTR)
     button_bounds.origin.x += button_bounds.size.width - TREE_VIEW_DRAG_WIDTH;
index 21a1ff3333c9cdf483f3b06b0a8cc23f3583f9b5..ab2f2195518eebf571ac75439d4e6d4227d5bdfc 100644 (file)
@@ -2544,10 +2544,11 @@ _gtk_widget_emulate_press (GtkWidget      *widget,
     return;
 
   gdk_event_get_coords (event, &x, &y);
-  gtk_widget_compute_point (event_widget,
-                            gtk_widget_get_toplevel (event_widget),
-                            &GRAPHENE_POINT_INIT (x, y),
-                            &p);
+  if (!gtk_widget_compute_point (event_widget,
+                                 gtk_widget_get_toplevel (event_widget),
+                                 &GRAPHENE_POINT_INIT (x, y),
+                                 &p))
+      return;
 
   if (event->any.type == GDK_TOUCH_BEGIN ||
       event->any.type == GDK_TOUCH_UPDATE ||
@@ -3863,13 +3864,19 @@ gtk_widget_get_surface_allocation (GtkWidget     *widget,
 
   g_assert (GTK_IS_WINDOW (parent) || GTK_IS_POPOVER (parent));
 
-  gtk_widget_compute_bounds (widget, parent, &bounds);
-  *allocation = (GtkAllocation){
-    floorf (bounds.origin.x),
-    floorf (bounds.origin.y),
-    ceilf (bounds.size.width),
-    ceilf (bounds.size.height)
-  };
+  if (gtk_widget_compute_bounds (widget, parent, &bounds))
+    {
+      *allocation = (GtkAllocation){
+        floorf (bounds.origin.x),
+        floorf (bounds.origin.y),
+        ceilf (bounds.size.width),
+        ceilf (bounds.size.height)
+      };
+    }
+  else
+    {
+      *allocation = (GtkAllocation) { 0, 0, 0, 0 };
+    }
 }
 
 static void
@@ -5120,9 +5127,9 @@ _gtk_widget_run_controllers (GtkWidget           *widget,
   return handled;
 }
 
-static void
+static gboolean
 translate_event_coordinates (GdkEvent  *event,
-                       GtkWidget *widget);
+                             GtkWidget *widget);
 gboolean
 _gtk_widget_captured_event (GtkWidget      *widget,
                             const GdkEvent *event)
@@ -5138,7 +5145,11 @@ _gtk_widget_captured_event (GtkWidget      *widget,
     return TRUE;
 
   event_copy = gdk_event_copy (event);
-  translate_event_coordinates (event_copy, widget);
+  if (!translate_event_coordinates (event_copy, widget))
+    {
+      g_object_unref (event_copy);
+      return FALSE;
+    }
 
   return_val = _gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_CAPTURE);
 
@@ -5196,7 +5207,7 @@ event_surface_is_still_viewable (const GdkEvent *event)
     }
 }
 
-static void
+static gboolean
 translate_event_coordinates (GdkEvent  *event,
                              GtkWidget *widget)
 {
@@ -5205,16 +5216,19 @@ translate_event_coordinates (GdkEvent  *event,
   graphene_point_t p;
 
   if (!gdk_event_get_coords (event, &x, &y))
-    return;
+    return TRUE;
 
   event_widget = gtk_get_event_widget (event);
 
-  gtk_widget_compute_point (event_widget,
-                            widget,
-                            &GRAPHENE_POINT_INIT (x, y),
-                            &p);
+  if (!gtk_widget_compute_point (event_widget,
+                                 widget,
+                                 &GRAPHENE_POINT_INIT (x, y),
+                                 &p))
+    return FALSE;
 
   gdk_event_set_coords (event, p.x, p.y);
+
+  return TRUE;
 }
 
 static gboolean
@@ -5237,7 +5251,11 @@ gtk_widget_event_internal (GtkWidget      *widget,
 
   event_copy = gdk_event_copy (event);
 
-  translate_event_coordinates (event_copy, widget);
+  if (!translate_event_coordinates (event_copy, widget))
+    {
+      g_object_unref (event_copy);
+      return FALSE;
+    }
 
   if (widget == gtk_get_event_target (event_copy))
     return_val |= _gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_TARGET);
index 79177311d4dd010b0524c71e325ff5b27cebb758..af68bd7a563cd3dfd8f319fb3b7baf9e27124247 100644 (file)
@@ -80,8 +80,9 @@ tab_sort_func (gconstpointer a,
   GtkTextDirection text_direction = GPOINTER_TO_INT (user_data);
   float y1, y2;
 
-  gtk_widget_compute_bounds (child1, gtk_widget_get_parent (child1), &child_bounds1);
-  gtk_widget_compute_bounds (child2, gtk_widget_get_parent (child2), &child_bounds2);
+  if (!gtk_widget_compute_bounds (child1, gtk_widget_get_parent (child1), &child_bounds1) ||
+      !gtk_widget_compute_bounds (child2, gtk_widget_get_parent (child2), &child_bounds2))
+    return 0;
 
   y1 = child_bounds1.origin.y + (child_bounds1.size.height / 2.0f);
   y2 = child_bounds2.origin.y + (child_bounds2.size.height / 2.0f);
@@ -178,8 +179,9 @@ axis_compare (gconstpointer a,
   int start1, end1;
   int start2, end2;
 
-  gtk_widget_compute_bounds (*((GtkWidget **)a), compare->widget, &bounds1);
-  gtk_widget_compute_bounds (*((GtkWidget **)b), compare->widget, &bounds2);
+  if (!gtk_widget_compute_bounds (*((GtkWidget **)a), compare->widget, &bounds1) ||
+      !gtk_widget_compute_bounds (*((GtkWidget **)b), compare->widget, &bounds2))
+    return 0;
 
   get_axis_info (&bounds1, compare->axis, &start1, &end1);
   get_axis_info (&bounds2, compare->axis, &start2, &end2);
@@ -278,7 +280,8 @@ focus_sort_left_right (GtkWidget        *widget,
       graphene_rect_t old_focus_bounds;
 
       parent = gtk_widget_get_parent (widget);
-      gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds);
+      if (!gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds))
+        graphene_rect_init (&bounds, 0, 0, 0, 0);
 
       if (old_focus_coords (widget, &old_focus_bounds))
         {
@@ -379,7 +382,8 @@ focus_sort_up_down (GtkWidget        *widget,
       graphene_rect_t old_focus_bounds;
 
       parent = gtk_widget_get_parent (widget);
-      gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds);
+      if (!gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds))
+        graphene_rect_init (&bounds, 0, 0, 0, 0);
 
       if (old_focus_coords (widget, &old_focus_bounds))
         {
index 531b1332fc9a5d75ad20af549f1ac02538bde6de..23a359d204febd2c9dc9b86491d0f6b7c1e8a0fe 100644 (file)
@@ -96,11 +96,17 @@ gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
 
       gtk_snapshot_push_clip (snapshot,
                               &GRAPHENE_RECT_INIT(0, 0, width, height));
-      gtk_widget_compute_bounds (self->widget, self->widget, &bounds);
-      graphene_matrix_init_from_2d (&transform,
-                                    width / bounds.size.width, 0.0,
-                                    0.0, height / bounds.size.height,
-                                    bounds.origin.x, bounds.origin.y);
+      if (gtk_widget_compute_bounds (self->widget, self->widget, &bounds))
+        {
+          graphene_matrix_init_from_2d (&transform,
+                                        width / bounds.size.width, 0.0,
+                                        0.0, height / bounds.size.height,
+                                        bounds.origin.x, bounds.origin.y);
+        }
+      else
+        {
+          graphene_matrix_init_identity (&transform);
+        }
       gtk_snapshot_push_transform (snapshot, &transform);
 
       gtk_widget_snapshot (self->widget, snapshot);
@@ -269,7 +275,8 @@ gtk_widget_paintable_snapshot_widget (GtkWidgetPaintable *self)
   if (self->widget == NULL)
     return gdk_paintable_new_empty (0, 0);
 
-  gtk_widget_compute_bounds (self->widget, self->widget, &bounds);
+  if (!gtk_widget_compute_bounds (self->widget, self->widget, &bounds))
+    return gdk_paintable_new_empty (0, 0);
 
   if (self->widget->priv->render_node == NULL)
     return gdk_paintable_new_empty (bounds.size.width, bounds.size.height);
index 07ff181dd3c986e371981be05486befb3e4ad2dc..616781e7b1c90255e56b1e72a177ab39fb41e49a 100644 (file)
@@ -158,6 +158,7 @@ gtk_fps_overlay_snapshot (GtkInspectorOverlay *overlay,
   double fps;
   char *fps_string;
   graphene_rect_t bounds;
+  gboolean has_bounds;
   int width, height;
   double overlay_opacity;
 
@@ -202,20 +203,20 @@ gtk_fps_overlay_snapshot (GtkInspectorOverlay *overlay,
   if (GTK_IS_WINDOW (widget))
     {
       GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
-      if (child)
-        gtk_widget_compute_bounds (child, widget, &bounds);
-      else
-        gtk_widget_compute_bounds (widget, widget, &bounds);
+      if (!child ||
+          !gtk_widget_compute_bounds (child, widget, &bounds))
+        has_bounds = gtk_widget_compute_bounds (widget, widget, &bounds);
     }
   else
     {
-      gtk_widget_compute_bounds (widget, widget, &bounds);
+      has_bounds = gtk_widget_compute_bounds (widget, widget, &bounds);
     }
 
   layout = gtk_widget_create_pango_layout (widget, fps_string);
   pango_layout_get_pixel_size (layout, &width, &height);
 
-  gtk_snapshot_offset (snapshot, bounds.origin.x + bounds.size.width - width, bounds.origin.y);
+  if (has_bounds)
+    gtk_snapshot_offset (snapshot, bounds.origin.x + bounds.size.width - width, bounds.origin.y);
   if (overlay_opacity < 1.0)
     gtk_snapshot_push_opacity (snapshot, overlay_opacity);
   gtk_snapshot_append_color (snapshot,
@@ -226,7 +227,8 @@ gtk_fps_overlay_snapshot (GtkInspectorOverlay *overlay,
                               &(GdkRGBA) { 1, 1, 1, 1 });
   if (overlay_opacity < 1.0)
     gtk_snapshot_pop (snapshot);
-  gtk_snapshot_offset (snapshot, - bounds.origin.x - bounds.size.width + width, - bounds.origin.y);
+  if (has_bounds)
+    gtk_snapshot_offset (snapshot, - bounds.origin.x - bounds.size.width + width, - bounds.origin.y);
   g_free (fps_string);
 
   gtk_widget_add_tick_callback (widget, gtk_fps_overlay_force_redraw, NULL, NULL);
index 65c78825ccbd59f7c3a0882d23140e5002341489..9200335cdb0c29be88c8b29016e590140f0917c5 100644 (file)
@@ -153,10 +153,10 @@ gtk_transform_tester_snapshot (GtkWidget   *widget,
 
   GTK_WIDGET_CLASS (gtk_transform_tester_parent_class)->snapshot (widget, snapshot);
 
-  if (!do_picking)
+  if (!do_picking ||
+      !gtk_widget_compute_bounds (self->test_widget, widget, &child_bounds) ||
+      !gtk_widget_compute_bounds (self->test_widget, self->test_widget, &self_bounds))
     return;
-  gtk_widget_compute_bounds (self->test_widget, widget, &child_bounds);
-  gtk_widget_compute_bounds (self->test_widget, self->test_widget, &self_bounds);
 
   {
     const struct {